/**
 * Copyright 2010 Balaji Thennarangam.
 */
package com.kathez.logging;

import java.util.logging.Level;

import com.kathez.util.commonutils.KathezUtils;
import com.kathez.util.commonutils.PropertyLoader;

/**
 * Factory class that returns a IKathezLogger.
 * The actual implementation of he Logger may vary based on the input
 * 
 * @author Balaji T
 *
 */
public class KathezLoggerFactory {
	
	public static IKathezLogger getLogger(){
		IKathezLogger logger = null;
		String loggerClassName = KathezUtils.nullifyEmpty(PropertyLoader.getProperty("logger_class"));
		if(loggerClassName != null){
			try {
				logger = (IKathezLogger)Class.forName(loggerClassName).newInstance();
			} catch (InstantiationException e) {
				logger = new KathezLogger();
				logger.getLogger(KathezLoggerFactory.class).log(Level.WARNING, "Could not instantiate "+loggerClassName+".Default Logger is returned");
			} catch (IllegalAccessException e) {
				logger = new KathezLogger();
				logger.getLogger(KathezLoggerFactory.class).log(Level.WARNING, "IllegalAccessException during instantiation of "+loggerClassName+".Default Logger is returned");
			} catch (ClassNotFoundException e) {
				logger = new KathezLogger();
				logger.getLogger(KathezLoggerFactory.class).log(Level.WARNING, "Class not found exception for "+loggerClassName+".Default Logger is returned");
			}
		}else{
			logger = new KathezLogger();
		}
		
		return logger;
	}
}
